﻿/******************************************************************************
 *  Project:		Neddle Community Edition
 *  Filename:		TypeExtensions.cs
 *	Created By:     Kristopher Cargile <kristopher@neddle.org>
 *  Date Created:	March 29, 2011
 * ****************************************************************************
 * IMPORTANT GNU LICENSE INFORMATION. DO NOT REMOVE THIS SECTION!
 * 
 * Neddle :: Copyright (c) 2010-2012, Cargile Technology Group, LLC
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 ******************************************************************************/

using System;

namespace Neddle 
{
    /// <summary>
    /// TypeExtensions
    /// </summary>
    public static class TypeExtensions
    {
        /// <summary>
        /// Determines whether the specified t is nullable.
        /// </summary>
        /// <param name="t">The t.</param>
        /// <returns>
        /// 	<c>true</c> if the specified t is nullable; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsNullable(this Type t)
        {
            return (t.IsGenericType && t.GetGenericTypeDefinition().Equals(typeof(Nullable<>)));
        }

        /// <summary>
        /// Gets the domainobject type.
        /// </summary>
        /// <param name="param">The param.</param>
        /// <returns></returns>
        public static Type GetDomainType(this Type param)
        {
            param.CheckNull("param");
            if (param.Name.Contains("_Wrapped_"))
            {
                param = param.BaseType;
            }
            return param;
        }
    }
}


